package com.newx.common.core.enums.business;

import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public enum KlineIntervalEnum {
    //1是1分钟K，2是5分钟K，3是15分钟K，4是30分钟K，5是小时K，6是2小时K(股票不支持2小时)，7是4小时K(股票不支持4小时)，8是日K，9是周K，10是月K （注：股票不支持2小时K、4小时K）
    ONE_MINUTE(1, "1m"),
    FIVE_MINUTES(2, "5m"),
    FIFTEEN_MINUTES(3, "15m"),
    THIRTY_MINUTES(4, "30m"),
    ONE_HOUR(5, "1h"),
    ONE_DAY(8, "1d"),
    ONE_WEEK(9, "1w"),
    ONE_MONTH(10, "1M");

    private final Integer code;
    private final String interval;

    public static String fromCode(Integer code) {
        for (KlineIntervalEnum kLineIntervalEnum : values()) {
            if (kLineIntervalEnum.code.equals(code)) {
                return kLineIntervalEnum.interval;
            }
        }
        throw new IllegalArgumentException("Invalid K-Line interval code: " + code);
    }

    public static Integer fromInterval(String interval) {
        for (KlineIntervalEnum kLineIntervalEnum : values()) {
            if (kLineIntervalEnum.interval.equals(interval)) {
                return kLineIntervalEnum.code;
            }
        }
        throw new IllegalArgumentException("Invalid K-Line interval: " + interval);
    }


}
